import 'package:flutter/material.dart';

class HouseItem extends StatefulWidget {
// const  HouseItem({super.key});
  HouseItem({super.key, required this.houseInfo});

  Map houseInfo;

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  Map houseInfo = {
    "building": '10号楼',
    "point": '鹤山碧桂园·黄金时代',
    "id": 7021647506464768,
    "name": '戚俊杰',
    "mobile": 13392052136,
    "room": '517 室',
    "gender": 1,
    "status": 2
  };

  @override
  void initState() {
    super.initState();
    setState(() {
      houseInfo = widget.houseInfo;
    });
  }

  // Tag 自定义组件
  Widget tagBuild(int state) {
    // 状态
    List tagList = [
      {},
      {
        "bg": const Color.fromARGB(50, 91, 177, 227),
        "textColor": Color.fromARGB(255, 85, 145, 175),
        "desc": '审核中',
      },
      {
        "bg": const Color.fromARGB(255, 91, 243, 91),
        "textColor": Color.fromRGBO(1, 50, 1, 1),
        "desc": '审核成功',
      },
      {
        "bg": const Color.fromARGB(255, 247, 129, 133),
        "textColor": Color.fromARGB(255, 84, 1, 1),
        "desc": '审核失败',
      },
    ];

    return Container(
        padding: const EdgeInsets.only(left: 5, right: 5, top: 2, bottom: 2),
        decoration: BoxDecoration(
            color: tagList[state]['bg'],
            borderRadius: BorderRadius.circular(5)),
        child: Text(tagList[state]['desc'],
            style: TextStyle(color: tagList[state]['color'])));
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, '/houseDetail', arguments: {'id': houseInfo['id']});
      },
      child: Container(
          padding: const EdgeInsets.all(10),
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          child: Column(
            children: [
              Row(
                children: [
                  Expanded(child: Text("${houseInfo['point']}")),
                  const Spacer(),
                  tagBuild(houseInfo['status']),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  Text(
                    '房间号',
                    style: TextStyle(color: Colors.grey),
                  ),
                  Spacer(),
                  Expanded(
                      child: Text(
                    "${houseInfo['building']} ${houseInfo['room']}",
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  Text(
                    '业主',
                    style: TextStyle(color: Colors.grey),
                  ),
                  Spacer(),
                  Expanded(
                      child: Text(
                    "${houseInfo['name']}",
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
            ],
          )),
    );
  }
}
